export const asyncLoginTY = ()=>{
  return new Promise((reslove,reject)=>{
    TY.logout()
    if (TY.USER.isLogin()) {
      console.log('已经登录')
      return reslove(true)
    }
    const server_url = 'https://200.telyes.net'
    const in_user = 'MFXX1'
    const in_password = 'MFmf@2019'
    // 初始化
    TY.URL.initServerUrl(server_url)
    // 登录
    TY.login({ account: in_user, password: in_password, serverUrl: server_url }, (resp) => {
      // 登录成功
      console.log('TY登录成功')
      TY.USER.initSocket(()=>{
        console.info('socket 连接成功')
        reslove(true)
      },()=>{
        console.error('socket 连接失败')
        reslove(false)
      })
    }, (resp) => {
      console.log('TY登录失败', resp)
      reject(false)
    })
  })
}


export async function loginTY() {

  if (TY.USER.isLogin()) {
    return Promise.resolve(true)
  }
  const server_url = 'https://200.telyes.net'
  const in_user = 'MFXX1'
  const in_password = 'MFmf@2019'
  // 初始化
  TY.URL.initServerUrl(server_url)
  // 登录
  await TY.login({ account: in_user, password: in_password, serverUrl: server_url }, (resp) => {
    TY.USER.setUser(localStorage.getItem('token'), localStorage.getItem('uid'))
    // 登录成功
    console.log('TY登录成功')
    TY.USER.initSocket(function() {
      console.info('socket 连接成功')
    }, function() {
      console.error('socket 连接失败')
    })
    return Promise.resolve(true)
  }, (resp) => {
    console.log('TY登录失败', resp)
    return Promise.resolve(false)
  })
}
